package com.example.mfbq.adapter;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mfbq.R;
import com.example.mfbq.arithmetic.Process;

import java.util.List;

public class DataAdapter extends RecyclerView.Adapter<DataAdapter.DataViewHolder> {

    private List<Integer> list;
    private Process[] processes;

    public DataAdapter(List<Integer> list, Process[] processes){
        this.list = list;
        this.processes = processes;
    }

    @NonNull
    @Override
    public DataViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        DataViewHolder dataViewHolder = new DataViewHolder(View.inflate(parent.getContext(), R.layout.data_square_item, null));
        return dataViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final DataViewHolder holder, int position) {
        if(list.get(position) == -1){
            holder.tv.setText("闲");
            holder.tv.setTextColor(Color.rgb(0,133,119));
        }else{
            holder.tv.setText(list.get(position)+"");
            holder.tv.setTextColor(Color.BLACK);
        }
        holder.now.setText(position+"");
        holder.next.setText((position+1)+"");

    }

    @Override
    public int getItemCount() {
        return this.list.size();
    }

    public void add(int id){
        this.list.add(id);
        notifyItemInserted(this.list.size());
    }
    public void remove(){
        this.list.remove(0);
        notifyItemRemoved(0);
    }
    public void clear(){
        this.list.clear();
        notifyDataSetChanged();
    }
    private Process getProcess(int id){
        for(Process p : this.processes){
            if(p.getProcessId() == id){
                return p;
            }
        }
        return null;
    }

    class DataViewHolder extends RecyclerView.ViewHolder{
        TextView tv;
        TextView now;
        TextView next;
        public DataViewHolder(View view){
            super(view);
            this.tv = view.findViewById(R.id.data_id);
            this.now = view.findViewById(R.id.now);
            this.next = view.findViewById(R.id.next);
        }
    }
}
